﻿using UnityEngine;
using System.Collections;
using Dict.DataModel;
using Dict.Blo;

namespace UI
{
    public class MineIcon : MonoBehaviour
    {
        public TextureKit mineIcon;
        public UILabel labCount;
        public UILabel labLevel;
        public GameObject chosedImg;
        public GameObject widgetForBag;
        public UISprite levelBg;
        string m_mineId;
        public string MineId
        {
            get
            {
                return m_mineId;
            }
        }

        public delegate void ItemClickCallback(string mineId);
        public ItemClickCallback m_callback;

        System.Diagnostics.Stopwatch stopWatch;

        void Awake()
        {
            labCount.gameObject.SetActive(false);
        }

        public void SetMine(string id)
        {
            m_mineId = id;

            TableMineSkill mineData = DictMineBlo.GetTableMineSkill(id);

            if (mineData != null)
            {
                mineIcon.textureName = mineData.MineItemID;
            }
            else
            {
                return;
            }

            if(levelBg != null)
            {
                if (mineData.Level != 0)
                {
                    levelBg.gameObject.SetActive(true);
                    switch (mineData.Quality)
                    {
                        case (int)QualityValue.RED:
                            levelBg.spriteName = "UI_kuang_lv_bi_red";
                            break;
                        case (int)QualityValue.PURPLE:
                            levelBg.spriteName = "UI_kuang_lv_bi_zi";
                            break;
                        case (int)QualityValue.GREEN:
                            levelBg.spriteName = "UI_kuang_lv_bi_green";
                            break;
                        case (int)QualityValue.YELLOW:
                            levelBg.spriteName = "UI_kuang_lv_bi_yellow";
                            break;
                        case (int)QualityValue.BLUE:
                            levelBg.spriteName = "UI_kuang_lv_bi_blue";
                            break;
                        case (int)QualityValue.WHITE:
                            levelBg.spriteName = "UI_kuang_lv_bi_white";
                            break;
                    }
                    labLevel.text = mineData.Level.ToString();
                }
                else
                {
                    levelBg.gameObject.SetActive(false);
                }
            }
        }

        public void UpdateCount(string text, UIWidget.Pivot pivot = UIWidget.Pivot.Center)
        {
            labCount.gameObject.SetActive(true);
            labCount.pivot = pivot;
            labCount.text = text;
        }

        public void OnClick()
        {
            if (m_callback != null)
            {
                Debug.Log("callback in click");
                m_callback(m_mineId);
            }
        }
    }
}

